package com.smooth.site.sx.pc.base.controller;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smooth.common.site.common.rsp.ReturnResult;
import com.smooth.dao.gen.BaseCollegeMapper;
import com.smooth.dao.gen.BaseSchSubjectMapper;
import com.smooth.dao.gen.bean.BaseCollege;
import com.smooth.dao.gen.bean.BaseSchSubject;
import com.smooth.dao.gen.bean.BaseSchSubjectExample;
import com.smooth.site.sx.mag.basedata.college.service.BaseCollegeService;
import com.smooth.site.sx.pc.base.req.QueryCollegeReq;
import com.smooth.site.sx.pc.base.rsp.BaseCollegeRsp;
import com.smooth.site.sx.pc.base.rsp.BaseSchSubjectRsp;

@Controller
@RequestMapping(value = "/pc")
public class PcSchoolController {
	@Autowired
	BaseCollegeService baseCollegeService;
	@Autowired
	BaseCollegeMapper baseCollegeMapper;
	@Autowired
	BaseSchSubjectMapper baseSchSubjectMapper;
	/**
	 * 学生注册
	 * @param studenRegVo
	 * @param result
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = {"p/basedata/col/query"},method = {RequestMethod.POST,RequestMethod.GET})
	@ResponseBody
	public ReturnResult register(@Valid QueryCollegeReq queryCollegeReq, BindingResult result,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		List<BaseCollege> blist = baseCollegeService.queryCollege(queryCollegeReq);
		returnResult.setData(BaseCollegeRsp.getRsp(blist));
		return returnResult;
	}
	
	
	@RequestMapping(value = { "p/subject/query" }, method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ReturnResult query(@RequestParam(required=true) String schId,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		
		BaseSchSubjectExample baseSchSubjectExample = new BaseSchSubjectExample();
		BaseSchSubjectExample.Criteria criteria = baseSchSubjectExample.createCriteria();
		
		criteria.andSchIdEqualTo(schId);
		
		List<BaseSchSubject> bslist = baseSchSubjectMapper.selectByExample(baseSchSubjectExample);
		
		returnResult.setData(BaseSchSubjectRsp.getRsp(bslist));
		return returnResult;
	}
	
	
	@RequestMapping(value = { "p/xueyuan/query" }, method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ReturnResult xueyuanQuery(@RequestParam(required=true) String schId,HttpServletRequest request, HttpServletResponse response) {
		ReturnResult returnResult = new ReturnResult();
		
		BaseSchSubjectExample baseSchSubjectExample = new BaseSchSubjectExample();
		BaseSchSubjectExample.Criteria criteria = baseSchSubjectExample.createCriteria();
		
		criteria.andSchIdEqualTo(schId);
		
		List<BaseSchSubject> bslist = baseSchSubjectMapper.selectByExample(baseSchSubjectExample);
		Set<String> slist = new HashSet<String>();
		for(BaseSchSubject baseSchSubject : bslist) {
			slist.add(baseSchSubject.getFaculty());
		}
		returnResult.setData(slist);
		return returnResult;
	}
	
	
}
